home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / mkmf / mkmf.test < prev    next >
Text File  |  1989-10-10  |  2KB  |  77 lines

  1. #!/bin/csh -f
  2. #
  3. # A script to generate (or regenerate) the Makefile for a test directory.
  4. # If ./Makefile.proto exists, use it, else use a common prototype.
  5. #
  6. # We assume we were invoked from mkmf, thus we don't need to alter the
  7. # path, and MKMFDIR is in the environment to tell us where to find prototype
  8. # makefiles, etc.
  9. #
  10. # Variables:
  11. #    prog        program to create (directories are assumed to be named
  12. #            after the programs they create)
  13. #    pref        prefix pattern that files must match to be included
  14. #    makefile    name of the makefile to create
  15. #    MKMFDIR        directory containing prototype makefiles
  16. #
  17. set prog=$cwd:t
  18. set pref='[a-z_A-Z]'
  19.  
  20. if ($?MAKEFILE) then
  21.     set makefile=$MAKEFILE
  22. else
  23.     set makefile=Makefile
  24. endif
  25.  
  26. set distdir=($DISTDIR)
  27.  
  28. if (-e $makefile.proto) then
  29.     set proto=$makefile.proto
  30. else
  31.     set proto="${MKMFDIR}/Makefile.test"
  32. endif
  33.  
  34. echo "Generating a Makefile for $prog using $proto"
  35.  
  36. #
  37. # First figure out what's there by way of .c, .y, .l, .s, .p, .h and .o files
  38. # If any one doesn't have any members, it'll contain the original
  39. # pattern (b/c of nonomatch). We want it to be empty, though, so
  40. # we reset it.
  41. #
  42. set nonomatch
  43. set srcs=( ${pref}*.[cylsp] )
  44. if ("$srcs" == "${pref}*.[cylsp]") set srcs=()
  45. set Hfiles=( ${pref}*.h )
  46. if ("$Hfiles" == "${pref}*.h") set Hfiles=()
  47. rm -f version.o
  48. set Ofiles=( ${pref}*.o )
  49. if ("$Ofiles" == "${pref}*.o") set Ofiles=()
  50. unset nonomatch
  51.  
  52. #
  53. # Merge in any .o files that can be created from local source files but don't
  54. # exist yet. In addition, figure out which .o files may be safely removed
  55. # during a "make clean" and store them in RmOfiles.
  56. #
  57. set RmOfiles=""
  58. if ("$srcs" != "") then
  59.     foreach file ($srcs)
  60.         set file=$file:r.o
  61.         set RmOfiles=($RmOfiles $file)
  62.         if (! -e $file) set Ofiles=($Ofiles $file)
  63.     end
  64. endif
  65.  
  66. cat $proto | sed \
  67.     -e "s,@(PROGRAM),$prog,g" \
  68.     -e "s,@(OBJS),$Ofiles,g" \
  69.     -e "s,@(CLEANOBJS),$RmOfiles,g" \
  70.     -e "s,@(SRCS),$srcs,g" \
  71.     -e "s,@(HDRS),$Hfiles,g" \
  72.     -e "s,@(MAKEFILE),$makefile,g" \
  73.     -e "s,@(TEMPLATE),$proto,g" \
  74.     -e "s,@(DISTDIR),$distdir,g" \
  75.     -e "s,@(DATE),`date`,g" > $makefile
  76. endif
  77.